TARGETS := \
        mdriver \
        allocator_test

LOCKER=/afs/csail.mit.edu/proj/courses/6.172
CC := clang
# You can add -Werr to clang to force all warnings to turn into errors
CFLAGS := -std=gnu99 -g -Wall
LDFLAGS := -lm
# Macros defined by the user or OpenTuner
PARAMS :=

ifeq ($(GETTIME),1)
  CFLAGS += -DGET_RUNNINGTIME
endif

HEADERS := \
	allocator_interface.h \
	config.h \
	fsecs.h \
	mdriver.h \
	memlib.h \
	validator.h

# Blank line ends list.

# If you add a new file called "filename.c", you should
# add "filename.o \" to this list.
OBJS := \
	memlib.o

MDRIVER_OBJS:= \
	allocator.o \
	bad_allocator.o \
	clock.o \
	fcyc.o \
	fsecs.o \
	ftimer.o \
	libc_allocator.o \
	mdriver.o \
	my_allocator_wrappers.o

ALLOCATOR_TEST_OBJS:= \
	allocator.o \
	bad_allocator.o \
	libc_allocator.o \
	allocator_test.o \
	my_allocator_wrappers.o

# Blank line ends list.

ifeq ($(DEBUG),1)
  CFLAGS += -DDEBUG -O0
else
  CFLAGS += -DNDEBUG -O3
endif

CFLAGS += $(OTHER_CFLAGS)

# You shouldn't need to touch this.  This keeps track of whether or
# not you've changed CFLAGS.
OLD_CFLAGS := $(shell cat .cflags 2> /dev/null)
ifneq ($(CFLAGS),$(OLD_CFLAGS))
.cflags::
	@echo "$(CFLAGS)" > $@
endif

# make all targets specified
all: $(TARGETS)

.PHONY: pintool all partial_clean run clean

pintool:
	$(MAKE) -C pintool

mdriver: $(OBJS) $(MDRIVER_OBJS)
	$(CC) $(PARAMS) $(LDFLAGS) $(OBJS) $(MDRIVER_OBJS) -o $@

allocator_test: $(OBJS) $(ALLOCATOR_TEST_OBJS)
	$(CC) $(PARAMS) $(LDFLAGS) $(OBJS) $(ALLOCATOR_TEST_OBJS) -o $@

# compile objects

# pattern rule for building objects
%.o: %.c .cflags
	$(CC) $(PARAMS) $(CFLAGS) -c $*.c -o $@


# run each of the targets
run: $(TARGETS)
	for X in $(TARGETS) ; do \
		echo $$X -v ; \
		./$$X -v ; \
		echo ; \
	done

partial_clean::
	$(RM) -R $(TARGETS) $(OBJS) $(MDRIVER_OBJS) $(ALLOCATOR_TEST_OBJS) *.std* *.pyc
	$(RM) -R tmp/*.out

# remove targets and .o files as well as output generated by AWSRUN
clean: partial_clean
	$(RM) -R *.db* *.log
